﻿// See https://aka.ms/new-console-template for more information
//使用事件机制，模拟实现一个闹钟功能。闹钟可以有嘀嗒（Tick）事件和响铃（Alarm）
//两个事件。在闹钟走时时或者响铃时，在控制台显示提示信息。
namespace program2
{
    public class TimeEventArgs
    {
        public int x { get; set; }
        public int y { get; set; }
        public int z { get; set; }
    }
    public class Clock
    {
        public delegate void TickHandeler(Object sender, TimeEventArgs args);
        public delegate void AlarmHandeler(Object sender, TimeEventArgs args);

        public event TickHandeler OnTick;
        public event AlarmHandeler OnAlarm;

        public void Tick(int x, int y, int z)//时分秒
        {
            Console.WriteLine($"clock ticks on {x},{y},{z}");
            TimeEventArgs args = new TimeEventArgs()
            {
                x = x,
                y = y,
                z = z
            };
            OnTick(this, args);
        }

        public void Alarm(int x, int y, int z)
        {
            Console.WriteLine($"clock alarms on {x},{y},{z}");
            TimeEventArgs args = new TimeEventArgs()
            {
                x = x,
                y = y,
                z = z
            };
            OnAlarm(this, args);
        }
        public Clock()
        {
            OnTick += cl_Tick;
            OnAlarm+= cl_Alarm;
        }
        public void cl_Tick(Object sender, TimeEventArgs args)
        {
            Console.WriteLine("时钟滴答滴答");
        }
        public void cl_Alarm(Object sender, TimeEventArgs args)
        {
            Console.WriteLine("闹钟响了！");
        }

        static void Main(string[] args)
        {
            Clock clock = new Clock();
            clock.Tick(10, 53, 20);
            clock.Alarm(6, 40, 0);
        }
    }
}



